<?php
namespace Admin\Model;
use Think\Model;

class DepartmentModel extends Model {


    public function getAllDepartment() {
        return $this->select();
    }


    public function addDepartment($data) {
        $d = $this->where('name = "'. $data['name'] .'"')->select();
        if (!empty($d)) return '100201';

        $flag = $this->add($data);
        if ($flag !== false) return '000000';
        return '111111';

    }


    public function getDepartmentById($id) {
        return $this->find($id);
    }


    public function getDepartmentName($id) {
        return $this->where('id = '.$id)->getField('name');
    }


    public function editDepartment($data) {
        $flag = $this->save($data);
        if ($flag !== false) return '000000';
        return '111111';
    }

    public function delDepartment($id) {
        $flag = $this->delete($id);
        if ($flag !== false ) return '000000';
        return '111111';
    }

}